问题
- microk8s安装过程中,部分镜像需要从google的镜像仓库拉取,但是国内无法访问其镜像仓库, 故需要手动获取镜像再自行安装(从官方提供的google mirror仓库获取)
- microk8s不是使用的宿主机器的docker进程, 故不能简单的把自己获取的镜像重新tag来完成安装; 需要导出之后然后使用microk8s提供的镜像管理功能进行导入
解决原理
获取到你需要的镜像名称和版本之后 (参见后面的排查技巧)
docker pull mirrorgooglecontainers/$imageName:$imageVersion
docker tag mirrorgooglecontainers/$imageName:$imageVersion k8s.gcr.io/$imageName:$imageVersion
docker save k8s.gcr.io/$imageName:$imageVersion > $imageName.tar
microk8s.ctr -n k8s.io image import $imageName.tar
示例步骤
视你开启的插件而言,需要手动安装需要的镜像, 以我为例, 需要如下这些(注意版本可能不一样)
k8s.gcr.io/pause:3.1
k8s.gcr.io/heapster-influxdb-amd64:v1.3.3
k8s.gcr.io/heapster-grafana-amd64:v4.4.3
k8s.gcr.io/heapster-amd64:v1.5.2
k8s.gcr.io/kubernetes-dashboard-amd64:v1.8.3
gcr.io/google_containers/k8s-dns-dnsmasq-nanny-amd64:1.14.7
gcr.io/google_containers/k8s-dns-kube-dns-amd64:1.14.7
gcr.io/google_containers/k8s-dns-sidecar-amd64:1.14.7
安装脚本如下(可以根据原理做成通用脚本再传参安装):
docker pull mirrorgooglecontainers/pause:3.1
docker pull mirrorgooglecontainers/heapster-influxdb-amd64:v1.3.3
docker pull mirrorgooglecontainers/heapster-grafana-amd64:v4.4.3
docker pull mirrorgooglecontainers/kubernetes-dashboard-amd64:v1.8.3
docker pull mirrorgooglecontainers/heapster-amd64:v1.5.2
docker pull mirrorgooglecontainers/k8s-dns-dnsmasq-nanny-amd64:1.14.7
docker pull mirrorgooglecontainers/k8s-dns-kube-dns-amd64:1.14.7
docker pull mirrorgooglecontainers/k8s-dns-sidecar-amd64:1.14.7
docker tag mirrorgooglecontainers/pause:3.1 k8s.gcr.io/pause:3.1
docker tag mirrorgooglecontainers/heapster-influxdb-amd64:v1.3.3 k8s.gcr.io/heapster-influxdb-amd64:v1.3.3
docker tag mirrorgooglecontainers/heapster-grafana-amd64:v4.4.3 k8s.gcr.io/heapster-grafana-amd64:v4.4.3
docker tag mirrorgooglecontainers/kubernetes-dashboard-amd64:v1.8.3 k8s.gcr.io/kubernetes-dashboard-amd64:v1.8.3
docker tag mirrorgooglecontainers/heapster-amd64:v1.5.2 k8s.gcr.io/heapster-amd64:v1.5.2
docker tag mirrorgooglecontainers/k8s-dns-dnsmasq-nanny-amd64:1.14.7 gcr.io/google_containers/k8s-dns-dnsmasq-nanny-amd64:1.14.7
docker tag mirrorgooglecontainers/k8s-dns-kube-dns-amd64:1.14.7 gcr.io/google_containers/k8s-dns-kube-dns-amd64:1.14.7
docker tag mirrorgooglecontainers/k8s-dns-sidecar-amd64:1.14.7 gcr.io/google_containers/k8s-dns-sidecar-amd64:1.14.7
docker save k8s.gcr.io/pause > pause.tar
docker save k8s.gcr.io/heapster-influxdb-amd64 > heapster-influxdb-amd64.tar
docker save k8s.gcr.io/heapster-grafana-amd64 > heapster-grafana-amd64.tar
docker save k8s.gcr.io/kubernetes-dashboard-amd64 > kubernetes-dashboard-amd64.tar
docker save k8s.gcr.io/heapster-amd64 > heapster-amd64.tar
docker save gcr.io/google_containers/k8s-dns-dnsmasq-nanny-amd64 > k8s-dns-dnsmasq-nanny-amd64.tar
docker save gcr.io/google_containers/k8s-dns-kube-dns-amd64 > k8s-dns-kube-dns-amd64.tar
docker save gcr.io/google_containers/k8s-dns-sidecar-amd64 > k8s-dns-sidecar-amd64.tar
microk8s.ctr -n k8s.io image import pause.tar
microk8s.ctr -n k8s.io image import heapster-influxdb-amd64.tar
microk8s.ctr -n k8s.io image import heapster-grafana-amd64.tar
microk8s.ctr -n k8s.io image import kubernetes-dashboard-amd64.tar
microk8s.ctr -n k8s.io image import heapster-amd64.tar
microk8s.ctr -n k8s.io image import k8s-dns-dnsmasq-nanny-amd64.tar
microk8s.ctr -n k8s.io image import k8s-dns-kube-dns-amd64.tar
microk8s.ctr -n k8s.io image import k8s-dns-sidecar-amd64.tar
排查技巧
- 遇到问题时先通过
microk8s.kubectr get pods
查看是否是RUNNING状态, 如果不是,先按照上述方法解决镜像问题 - 查看具体的镜像版本时候可以通过
kubectl get pods --namespace=kube-system -o json |grep message
直接过滤出错误消息 - 注意namespace的选择, 特别是你自己定义了namespace之后
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。